<?php
/**
 * Created by PhpStorm.
 * User: junyv
 * Date: 2017/4/18
 * Time: 15:56
 */

namespace app\home\controller;


class Store extends Base
{
    private $uid;
    private $store_title;
    public function _initialize(){
        parent::_initialize();
        $this->uid = input('param.uid/d',0);
        $action = strtolower(request()->action());
        switch($action){
            case 'used':
                $t = '二手房';
                break;
            case 'rental':
                $t = '出租房';
                break;
            case 'ask':
                $t = '问答';
                break;
            case 'news':
                $t = '资讯';
                break;
            default:
                $t = '';
                break;
        }
        $this->store_title = $t;
        $this->assign('action',$action);
        $this->assign('title',$t);
        $this->getUerInfo();
    }
    public function index(){
        model('store')->where(['user_id'=>$this->uid])->setInc('hits');
        $this->assign('title','店铺首页');
        return $this->fetch();
    }
    public function used(){
        $where['user_id'] = $this->uid;
        $where['status']  = 1;
        $field = 'id,estate_name,estate_id,title,price,total_price,img,file,ting,room,chu,wei,yang,address,tese,mianji';
        $lists = model('second_house')->where($where)->field($field)->paginate(10);
        $this->assign('lists',$lists);
        $this->assign('pages',$lists->render());
        return $this->fetch();
    }
    public function rental(){
        $where['user_id'] = $this->uid;
        $where['status']  = 1;
        $field = 'id,estate_name,estate_id,title,price,img,file,ting,room,chu,wei,yang,address,tese,mianji';
        $lists = model('rental')->where($where)->field($field)->paginate(10);
        $this->assign('lists',$lists);
        $this->assign('pages',$lists->render());
        return $this->fetch();
    }
    public function ask(){
        $cate = cache('askCate');
        $where['user_id'] = $this->uid;
        $where['status']  = 1;
        $lists = model('answer')->where($where)->order('id desc')->paginate(10);
        $this->assign('lists',$lists);
        $this->assign('pages',$lists->render());
        $this->assign('askCate',$cate['tree']);
        return $this->fetch();
    }
    public function news(){
        $where['user_id'] = $this->uid;
        $where['status']  = 1;
        $lists = model('article')->where($where)->field('id,title,img,description')->paginate(10);
        $this->assign('lists',$lists);
        $this->assign('pages',$lists->render());
        return $this->fetch();
    }
    private function getUerInfo(){
        $where['id'] = $this->uid;
        $field = 'id,nickname,mobile,headimgurl,chushou,chuzu,company,buy_phone,reg_time,login_time,email';
        $user  = model('user')->where($where)->field($field)->find();
        $store = model('store')->where(['user_id'=>$this->uid])->find();
        if($store){
            $store['title'] .= $this->store_title;
            $store['seo_title'] && $store['seo_title'] .= $this->store_title;
        }
        $this->setSeo($store);
        $this->assign('user',$user);
        $this->assign('store',$store);
    }

}